home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
asmexam.arc
/
DUMP.LST
< prev
next >
Wrap
File List
|
1984-09-03
|
22KB
|
459 lines
The Microsoft MACRO Assembler 09-03-84 PAGE 1-1
DUMP --- Display File Contents
1 name dump
2 page 55,132
3 title DUMP --- Display File Contents
4
5 ;DUMP --- a utility to display the contents of a file in hex
6 ;and ASCII format. Requires PC-DOS or MS-DOS 2.0.
7
8 ;Used in the form:
9 ;A>dump path\filename.ext [>device]
10 ;(item in square brackets is optional)
11
12 = 000D cr equ 0dh ;ASCII carriage return
13 = 000A lf equ 0ah ;ASCII line feed
14 = 0020 blank equ 20h ;ASCII space code
15
16 = 0080 command equ 80h ;buffer for command tail
17
18 = 0080 blksize equ 128 ;size of input file records
19
20 = 0001 output_handle equ 1 ;handle of standard output de
21 ;(can be redirected)
22 = 0002 error_handle equ 2 ;handle of standard error dev
23 ;(not redirectable)
24
25 0000 cseg segment para public 'CODE'
26
27 assume cs:cseg,ds:data,es:data,ss:stack
28
29 0000 dump proc far ;entry point from PC-DOS
30
31 0000 1E push ds ;save DS:0000 for final
32 0001 33 C0 xor ax,ax ;return to PC-DOS
33 0003 50 push ax
34 0004 B8 ---- R mov ax,data ;make our data segment
35 0007 8E C0 mov es,ax ;addressable via ES register.
36 0009 B4 30 mov ah,30h ;check version of PC-DOS.
37 000B CD 21 int 21h
38 000D 3C 02 cmp al,2
39 000F 73 0C jae dump1 ;proceed, DOS 2.0 or greater.
40 0011 BA 017E R mov dx,offset msg3 ;DOS 1.x --- print error mess
41 0014 8C C0 mov ax,es ;we must use the old PC-DOS
42 0016 8E D8 mov ds,ax ;string output function since
43 0018 B4 09 mov ah,9 ;handles are not available in
44 001A CD 21 int 21h ;this version of PC-DOS.
45 001C CB ret
46 001D E8 00A8 R dump1: call get_filename ;get path and file spec.for
47 ;input file from command line
48 0020 8C C0 mov ax,es ;set DS = ES for remainder
49 0022 8E D8 mov ds,ax ;of program.
50 0024 73 0A jnc dump2 ;jump,got acceptable name.
The Microsoft MACRO Assembler 09-03-84 PAGE 1-2
DUMP --- Display File Contents
51 0026 BA 016B R mov dx,offset msg2 ;missing or illegal filespec.
52 0029 B9 0013 90 mov cx,msg2_length
53 002D EB 75 90 jmp dump9 ;print error message and exit
54
55
56 0030 E8 00CB R dump2: call open_input ;now try to open input file
57 0033 73 0A jnc dump3 ;jump, opened input ok
58 0035 BA 0159 R mov dx,offset msg1 ;open of input file failed.
59 0038 B9 0012 90 mov cx,msg1_length
60 003C EB 66 90 jmp dump9 ;print error msg and exit.
61
62 003F E8 0101 R dump3: call read_block ;initialize input file buffer
63 0042 73 0A jnc dump4 ;jump,got a block
64 0044 BA 019B R mov dx,offset msg4 ;empty file, print error
65 0047 B9 000E 90 mov cx,msg4_length
66 004B EB 57 90 jmp dump9 ;message and exit
67
68
69 ;file successfully opened.
70 004E dump4: ;now convert and display it!
71 004E E8 00E1 R call get_char ;read 1 character from input.
72 0051 72 4D jc dump8 ;jump,end of file
73 0053 FF 06 0044 R inc input_addr ;update relative file positio
74
75 0057 0B DB or bx,bx ;is this 1st char of block?
76 0059 75 03 jnz dump5 ;no
77 005B E8 012F R call print_heading
78
79 005E 81 E3 000F dump5: and bx,0fh ;is this first byte of 16?
80 0062 75 0B jnz dump6 ;no, jump
81 0064 50 push ax ;save the byte
82 0065 BF 0048 R mov di,offset output ;convert relative file addr.
83 0068 A1 0044 R mov ax,input_addr ;for output string
84 006B E8 0147 R call conv_word
85 006E 58 pop ax
86 006F dump6: ;store ASCII version of chara
87 ;if it is alphanumeric,
88 006F BF 007F R mov di,offset outputb
89 0072 03 FB add di,bx ;calculate output string addr
90 0074 C6 05 2E mov byte ptr[di],'.' ;if it is control character,
91 0077 3C 20 cmp al,blank ;just print a dot.
92 0079 72 06 jb dump7 ;jump,not alphanumeric,
93 007B 3C 7E cmp al,7eh
94 007D 77 02 ja dump7 ;jump not alphanumberic,
95 007F 88 05 mov [di],al ;store ASCII character.
96 0081 dump7:
97 0081 53 push bx ; save current offset
98 0082 BF 004E R mov di,offset outputa ; offset of hex area
99 0085 03 FB add di,bx ; + 3*bx is where next
100 0087 03 FB add di,bx ; pair of hex digits go
The Microsoft MACRO Assembler 09-03-84 PAGE 1-3
DUMP --- Display File Contents
101 0089 03 FB add di,bx
102 008B E8 0152 R call conv_byte ;value => printable hex digits
103 008E 5B pop bx ;restore offset value
104 008F 83 FB 0F cmp bx,0fh ;16 bytes converted?
105 0092 75 BA jne dump4 ; no go back and do another
106 0094 BA 0048 R mov dx,offset output ;
107 0097 B9 0049 90 mov cx,output_length
108 009B E8 011F R call write_std
109 009E EB AE jmp dump4
110
111 00A0 dump8:
112 00A0 E8 00D8 R call close_input
113 00A3 CB ret
114
115 00A4 dump9:
116 00A4 E8 0127 R call write_error
117 00A7 CB ret
118
119 00A8 dump endp
120
121
122 00A8 get_filename proc near
123 00A8 BE 0080 mov si,offset command
124 00AB BF 0000 R mov di,offset input_name
125 00AE FC cld
126 00AF AC lodsb
127 00B0 0A C0 or al,al
128 00B2 74 15 jz get_filename4
129
130 00B4 get_filename1:
131 00B4 AC lodsb
132 00B5 3C 0D cmp al,cr
133 00B7 74 10 je get_filename4
134 00B9 3C 20 cmp al,blank
135 00BB 74 F7 jz get_filename1
136
137 00BD get_filename2:
138 00BD AA stosb
139 00BE AC lodsb
140 00BF 3C 0D cmp al,cr
141 00C1 74 04 je get_filename3
142 00C3 3C 20 cmp al,blank
143 00C5 75 F6 jne get_filename2
144
145 00C7 get_filename3:
146 00C7 F8 clc
147 00C8 C3 ret
148
149 00C9 get_filename4:
150 00C9 F9 stc
The Microsoft MACRO Assembler 09-03-84 PAGE 1-4
DUMP --- Display File Contents
151 00CA C3 ret
152
153 00CB get_filename endp
154
155 00CB open_input proc near
156 00CB BA 0000 R mov dx,offset input_name ; ds:dx => addr filename
157 00CE B0 00 mov al,0
158 00D0 B4 3D mov ah,3dh ; open file function in DOS
159 00D2 CD 21 int 21h
160 00D4 A3 0040 R mov input_handle,ax
161 00D7 C3 ret
162 00D8 open_input endp
163
164 00D8 close_input proc near
165 00D8 8B 1E 0040 R mov bx,input_handle
166 00DC B4 3E mov ah,3eh ; DOS closefile function number
167 00DE CD 21 int 21h
168 00E0 C3 ret
169 00E1 close_input endp
170
171 00E1 get_char proc near
172 00E1 8B 1E 0042 R mov bx,input_ptr
173 00E5 81 FB 0080 cmp bx,blksize ; is this the end of a block?
174 00E9 75 0C jne get_char1
175 00EB C7 06 0042 R 0000 mov input_ptr,0 ; if eob then set pointer to 0
176 00F1 E8 0101 R call read_block ; and get another block
177 00F4 73 EB jnc get_char
178 00F6 C3 ret
179
180 00F7 8A 87 00D9 R get_char1: mov al,[input_buffer+bx]
181 00FB FF 06 0042 R inc input_ptr
182 00FF F8 clc ; set carry 0 since not eof
183 0100 C3 ret
184
185 0101 get_char endp
186
187 0101 read_block proc near
188
189 0101 8B 1E 0040 R mov bx,input_handle
190 0105 B9 0080 mov cx,blksize
191 0108 BA 00D9 R mov dx,offset input_buffer
192 010B B4 3F mov ah,3fh ; dos read disk function
193 010D CD 21 int 21h
194 010F FF 06 0046 R inc input_block
195 0113 C7 06 0042 R 0000 mov input_ptr,0
196 0119 0B C0 or ax,ax ;ax contains # of bytes read
197 011B 75 01 jnz read_block1 ; if not eof ret (carry is 0)
198 011D F9 stc ; else set carry and ret
199
200 011E read_block1:
The Microsoft MACRO Assembler 09-03-84 PAGE 1-5
DUMP --- Display File Contents
201 011E C3 ret
202
203 011F read_block endp
204
205 011F write_std proc near
206
207 011F BB 0001 mov bx,output_handle
208 0122 B4 40 mov ah,40h ; write device function number
209 0124 CD 21 int 21h
210 0126 C3 ret
211
212 0127 write_std endp
213
214 0127 write_error proc near
215
216 0127 BB 0002 mov bx,error_handle
217 012A B4 40 mov ah,40h
218 012C CD 21 int 21h
219 012E C3 ret
220
221 012F write_error endp
222
223 012F print_heading proc near
224 012F 50 push ax
225 0130 53 push bx
226 0131 BF 009A R mov di,offset headinga
227 0134 A1 0046 R mov ax,input_block
228 0137 E8 0147 R call conv_word
229 013A BA 0091 R mov dx,offset heading
230 013D B9 0048 90 mov cx,heading_length
231 0141 E8 011F R call write_std
232 0144 5B pop bx
233 0145 58 pop ax
234 0146 C3 ret
235
236 0147 print_heading endp
237
238 0147 conv_word proc near
239 0147 50 push ax
240 0148 8A C4 mov al,ah
241 014A E8 0152 R call conv_byte
242 014D 58 pop ax
243 014E E8 0152 R call conv_byte
244 0151 C3 ret
245
246 0152 conv_word endp
247
248 0152 conv_byte proc near
249
250 0152 2A E4 sub ah,ah ; zero ah reg
The Microsoft MACRO Assembler 09-03-84 PAGE 1-6
DUMP --- Display File Contents
251 0154 B1 10 mov cl,16
252 0156 F6 F1 div cl
253 0158 E8 0163 R call ascii
254 015B AA stosb
255 015C 8A C4 mov al,ah
256 015E E8 0163 R call ascii
257 0161 AA stosb
258 0162 C3 ret
259
260 0163 conv_byte endp
261
262 0163 ascii proc near
263 0163 04 30 add al,'0' ; convert al to ascii char
264 0165 3C 39 cmp al,'9'
265 0167 7E 02 jle ascii2
266 0169 04 27 add al,'a'-'9'-1 ; offset to a-f hex range
267
268 016B C3 ascii2: ret
269 016C ascii endp
270 016C cseg ends
271
272 0000 data segment para public'DATA'
273
274 0000 40 [ input_name db 64 dup(0) ; buffer for input filespec
275 00
276 ]
277
278 0040 0000 input_handle dw 0 ;token from DOS for input file
279 0042 0000 input_ptr dw 0 ;pointer to input de-blocking buffer
280 0044 0000 input_addr dw 0 ; relatve address in file
281
282 0046 0000 input_block dw 0 ;current 128k block byte number
283 0048 6E 6E 6E 6E 20 20 output db 'nnnn',blank,blank
284 004E 10 [ outputa db 16 dup('00',blank)
285 30 30
286 20
287 ]
288
289 007E 20 db blank
290
291 007F 30 31 32 33 34 35 outputb db '0123456789abcdef',cr,lf
292 36 37 38 39 61 62
293 63 64 65 66 0D 0A
294 = 0049 output_length equ $-output
295 0091 0D 0A 52 65 63 6F heading db cr,lf,'Record',blank
296 72 64 20
297 009A 6E 6E 6E 6E 20 20 headinga db 'nnnn',blank,blank,cr,lf
298 0D 0A
299 00A2 07 [ db 7 dup(blank)
300 20
The Microsoft MACRO Assembler 09-03-84 PAGE 1-7
DUMP --- Display File Contents
301 ]
302
303 00A9 30 20 20 31 20 20 db '0 1 2 3 4 5 6 7 '
304 32 20 20 33 20 20
305 34 20 20 35 20 20
306 36 20 20 37 20 20
307 00C1 38 20 20 39 20 20 db '8 9 A B C D E F',cr,lf
308 41 20 20 42 20 20
309 43 20 20 44 20 20
310 45 20 20 46 0D 0A
311 = 0048 heading_length equ $-heading
312 00D9 80 [ input_buffer db blksize dup(?)
313 ??
314 ]
315
316 0159 0D 0A msg1 db cr,lf
317 015B 43 61 6E 6E 6F 74 db 'Cannot open file'
318 20 6F 70 65 6E 20
319 66 69 6C 65
320 = 0012 msg1_length equ $-msg1
321
322 016B 0D 0A msg2 db cr,lf
323 016D 4D 69 73 73 69 6E db 'Missing file name'
324 67 20 66 69 6C 65
325 20 6E 61 6D 65
326 = 0013 msg2_length equ $-msg2
327 017E 0D 0A msg3 db cr,lf
328 0180 52 65 71 75 69 72 db 'Requires DOS 2.0 or greater'
329 65 73 20 44 4F 53
330 20 32 2E 30 20 6F
331 72 20 67 72 65 61
332 74 65 72
333 = 001D msg3_length equ $-msg3
334
335 019B 0D 0A msg4 db cr,lf
336 019D 45 6D 70 74 79 20 db 'Empty file',cr,lf
337 66 69 6C 65 0D 0A
338 = 000E msg4_length equ $-msg4
339
340 01A9 data ends
341
342 0000 stack segment para stack'STACK'
343 0000 40 [ db 64 dup(?)
344 ??
345 ]
346
347
348 0040 stack ends
349 end dump
The Microsoft MACRO Assembler 09-03-84 PAGE Symbols-1
DUMP --- Display File Contents
Segments and groups:
N a m e Size align combine class
CSEG . . . . . . . . . . . . . . 016C PARA PUBLIC 'CODE'
DATA . . . . . . . . . . . . . . 01A9 PARA PUBLIC 'DATA'
STACK. . . . . . . . . . . . . . 0040 PARA STACK 'STACK'
Symbols:
N a m e Type Value Attr
ASCII. . . . . . . . . . . . . . N PROC 0163 CSEG Length =0009
ASCII2 . . . . . . . . . . . . . L NEAR 016B CSEG
BLANK. . . . . . . . . . . . . . Number 0020
BLKSIZE. . . . . . . . . . . . . Number 0080
CLOSE_INPUT. . . . . . . . . . . N PROC 00D8 CSEG Length =0009
COMMAND. . . . . . . . . . . . . Number 0080
CONV_BYTE. . . . . . . . . . . . N PROC 0152 CSEG Length =0011
CONV_WORD. . . . . . . . . . . . N PROC 0147 CSEG Length =000B
CR . . . . . . . . . . . . . . . Number 000D
DUMP . . . . . . . . . . . . . . F PROC 0000 CSEG Length =00A8
DUMP1. . . . . . . . . . . . . . L NEAR 001D CSEG
DUMP2. . . . . . . . . . . . . . L NEAR 0030 CSEG
DUMP3. . . . . . . . . . . . . . L NEAR 003F CSEG
DUMP4. . . . . . . . . . . . . . L NEAR 004E CSEG
DUMP5. . . . . . . . . . . . . . L NEAR 005E CSEG
DUMP6. . . . . . . . . . . . . . L NEAR 006F CSEG
DUMP7. . . . . . . . . . . . . . L NEAR 0081 CSEG
DUMP8. . . . . . . . . . . . . . L NEAR 00A0 CSEG
DUMP9. . . . . . . . . . . . . . L NEAR 00A4 CSEG
ERROR_HANDLE . . . . . . . . . . Number 0002
GET_CHAR . . . . . . . . . . . . N PROC 00E1 CSEG Length =0020
GET_CHAR1. . . . . . . . . . . . L NEAR 00F7 CSEG
GET_FILENAME . . . . . . . . . . N PROC 00A8 CSEG Length =0023
GET_FILENAME1. . . . . . . . . . L NEAR 00B4 CSEG
GET_FILENAME2. . . . . . . . . . L NEAR 00BD CSEG
GET_FILENAME3. . . . . . . . . . L NEAR 00C7 CSEG
GET_FILENAME4. . . . . . . . . . L NEAR 00C9 CSEG
HEADING. . . . . . . . . . . . . L BYTE 0091 DATA
HEADINGA . . . . . . . . . . . . L BYTE 009A DATA
HEADING_LENGTH . . . . . . . . . Number 0048
INPUT_ADDR . . . . . . . . . . . L WORD 0044 DATA
INPUT_BLOCK. . . . . . . . . . . L WORD 0046 DATA
INPUT_BUFFER . . . . . . . . . . L BYTE 00D9 DATA Length =0080
INPUT_HANDLE . . . . . . . . . . L WORD 0040 DATA
INPUT_NAME . . . . . . . . . . . L BYTE 0000 DATA Length =0040
INPUT_PTR. . . . . . . . . . . . L WORD 0042 DATA
LF . . . . . . . . . . . . . . . Number 000A
MSG1 . . . . . . . . . . . . . . L BYTE 0159 DATA
The Microsoft MACRO Assembler 09-03-84 PAGE Symbols-2
DUMP --- Display File Contents
MSG1_LENGTH. . . . . . . . . . . Number 0012
MSG2 . . . . . . . . . . . . . . L BYTE 016B DATA
MSG2_LENGTH. . . . . . . . . . . Number 0013
MSG3 . . . . . . . . . . . . . . L BYTE 017E DATA
MSG3_LENGTH. . . . . . . . . . . Number 001D
MSG4 . . . . . . . . . . . . . . L BYTE 019B DATA
MSG4_LENGTH. . . . . . . . . . . Number 000E
OPEN_INPUT . . . . . . . . . . . N PROC 00CB CSEG Length =000D
OUTPUT . . . . . . . . . . . . . L BYTE 0048 DATA
OUTPUTA. . . . . . . . . . . . . L BYTE 004E DATA Length =0010
OUTPUTB. . . . . . . . . . . . . L BYTE 007F DATA
OUTPUT_HANDLE. . . . . . . . . . Number 0001
OUTPUT_LENGTH. . . . . . . . . . Number 0049
PRINT_HEADING. . . . . . . . . . N PROC 012F CSEG Length =0018
READ_BLOCK . . . . . . . . . . . N PROC 0101 CSEG Length =001E
READ_BLOCK1. . . . . . . . . . . L NEAR 011E CSEG
WRITE_ERROR. . . . . . . . . . . N PROC 0127 CSEG Length =0008
WRITE_STD. . . . . . . . . . . . N PROC 011F CSEG Length =0008
Warning Severe
Errors Errors
0 0